package com.example.a517.myapplication;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

public class TestView extends ViewGroup {

    public TestView(Context context) {
        super(context);
    }

    public TestView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public TestView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        measureChildren(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int size = 0,size2=0;
        int mleft, mright, mtop, mbottom;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            int width = child.getMeasuredWidth();
            int height = child.getMeasuredHeight();

if (i==4){
    size2=size;
}
            if (i <= 4) {
                mleft = l + size;
                mright = width + size;
                mtop = ((b - height) / 2) + size;
                mbottom = (mtop + height);
                size += 120;
            } else {
                size2-=120;
                mleft = l + size;
                mright = width + size;
                mtop = ((b - height) / 2) + size2;
                mbottom = (mtop + height);
                size += 120;

            }
            child.layout(mleft, mtop, mright, mbottom);
        }


    }
}
